package com.foxmail.aroundme.boring.app;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;

import com.foxmail.aroundme.boring.utils.Key;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import com.tencent.bugly.crashreport.CrashReport;

/**
 * Created by gzl on 1/14/17.
 *
 */

public class App extends Application{

    private static Context mContext;

    private RefWatcher refWatcher;

    public static RefWatcher getRefWatcher(Context context) {
        App application = (App) context.getApplicationContext();
        return application.refWatcher;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;

        CrashReport.initCrashReport(getApplicationContext(), Key.bugly_key, true);
        //init LeakCanary
        refWatcher = LeakCanary.install(this);

    }

    // 获取ApplicationContext
    public static Context getContext() {
        return mContext;
    }

    /**
     * 获取根目录文件
     *
     * @return
     */
    public static String getRootPath() {
        String rootPath = "";
        if (mContext == null) {
            return "";
        }
        rootPath = mContext.getDir("agila", Context.MODE_PRIVATE).getAbsolutePath();
        if (TextUtils.isEmpty(rootPath)) {
            return "";
        }

        if (rootPath.endsWith("/")) {
            return rootPath;
        }
        return rootPath + "/";
    }
}
